package gui;

import java.awt.Color;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.Icon;
import javax.swing.ImageIcon;
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import Projektarbete.User;

/**
 *
 * @author Zhoujie/calle
 */

public class Contact extends javax.swing.JPanel {
	private User user;
    /**
     * Creates new form Kontakt
     * *
     */ 	
   public Contact(User user) {
	   this.user = user;
    	initComponents();
    	jLabel1.setText(user.getUserName());
    	
    	jCheckBox1.setName(user.getUserName()+" checkBox");
    	try {													
			java.net.URL frameIcon = new URL(
					"http://i46.tinypic.com/2qx435y.png");
			jLabel2.setIcon(new ImageIcon(frameIcon));

		} catch (MalformedURLException e1) {
			e1.printStackTrace();
		}
    	
    	if(user.isOnline()){
    		try {													
    			java.net.URL frameIcon = new URL(
    					"http://i46.tinypic.com/2cqod1t.png");
    			jLabel3.setIcon(new ImageIcon(frameIcon));

    		} catch (MalformedURLException e1) {
    			e1.printStackTrace();
    		}
    		
    	}
    	else{
    		try {													
    			java.net.URL frameIcon = new URL(
    					"http://i50.tinypic.com/2o55l.png");
    			jLabel3.setIcon(new ImageIcon(frameIcon));

    		} catch (MalformedURLException e1) {
    			e1.printStackTrace();
    		}
    	}
    	setBackground(Color.WHITE);
    }
   
   public User getUser(){
	   
	   return user;
   }
   
   public void setUser(User user){
	   this.user = user;
   }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

    	jLabel2 = new javax.swing.JLabel();
    	jCheckBox1 = new javax.swing.JCheckBox();
    	jLabel1 = new javax.swing.JLabel();
    	jLabel3 = new javax.swing.JLabel();

    	setMinimumSize(new java.awt.Dimension(220, 70));
    	setPreferredSize(new java.awt.Dimension(210, 70));

    	jLabel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    	jCheckBox1.setBackground(Color.WHITE);
    	jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
    	public void actionPerformed(java.awt.event.ActionEvent evt) {
    	jCheckBox1ActionPerformed(evt);
    	}
    	});

    	jLabel1.setFont(new java.awt.Font("Tahoma", 0, 16)); // NOI18N
    	jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    	jLabel1.setText("Name");

    	 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
         this.setLayout(layout);
         layout.setHorizontalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addGroup(layout.createSequentialGroup()
                 .addGap(2, 2, 2)
                 .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel1)
                     .addComponent(jCheckBox1))
                 .addGap(0, 73, Short.MAX_VALUE))
         );
         layout.setVerticalGroup(
             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
             .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
             .addGroup(layout.createSequentialGroup()
                 .addGap(0, 0, Short.MAX_VALUE)
                 .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                 .addGap(25, 25, 25))
             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                 .addContainerGap()
                 .addComponent(jLabel1)
                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                 .addComponent(jCheckBox1)
                 .addGap(0, 0, Short.MAX_VALUE))
         );
     }// 
    	private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
    	// TODO add your handling code here:
    	}
    	
    	public int getUserID(){
    		return user.getU_id();
    	}
    	
    	public boolean isChecked(){
    		return jCheckBox1.isSelected();
    	}
    	
    	public void setChecked(boolean checked){
    		jCheckBox1.setSelected(checked);
    	}
    	
    	public void setStatus(boolean status){
    		if(status){
        		try {													
        			java.net.URL frameIcon = new URL(
        					"http://i46.tinypic.com/2cqod1t.png");
        			jLabel3.setIcon(new ImageIcon(frameIcon));

        		} catch (MalformedURLException e1) {
        			e1.printStackTrace();
        		}
        		
        	}
        	else{
        		try {													
        			java.net.URL frameIcon = new URL(
        					"http://i50.tinypic.com/2o55l.png");
        			jLabel3.setIcon(new ImageIcon(frameIcon));

        		} catch (MalformedURLException e1) {
        			e1.printStackTrace();
        		}
        	}
    	}

    	// Variables declaration - do not modify
    	private javax.swing.JCheckBox jCheckBox1;
    	private javax.swing.JLabel jLabel1;
    	private javax.swing.JLabel jLabel2;
    	private javax.swing.JLabel jLabel3;
    	// End of variables declaration
    	}
